package com.caiju.health.controller;


import com.alibaba.excel.EasyExcel;
import com.caiju.health.constant.MessageConstant;
import com.caiju.health.dto.OrderSettingDTO;
import com.caiju.health.entity.PageResult;
import com.caiju.health.entity.Result;
import com.caiju.health.listener.CaijuEasyExcelListener;
import com.caiju.health.pojo.CheckItem;
import com.caiju.health.service.ICheackItemService;
import com.caiju.health.service.IOrderSettingService;
import com.caiju.health.vo.QueryPageBean;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/ordersetting")
@CrossOrigin    //允许跨域，因为不同端口号，认为不是同一个人
public class OrderSettingController {

    @Resource
    private CaijuEasyExcelListener caijuEasyExcelListener;

    @Resource
    private IOrderSettingService orderSettingService;

    @PostMapping("/upload")
    public Result upload(@RequestBody MultipartFile excelFile) throws IOException {
//        1.获取excelFile中 excel文件的内容
        InputStream in =excelFile.getInputStream();
//        2.借助阿里easyExcel解析流的数据
        EasyExcel.read(in, OrderSettingDTO.class,caijuEasyExcelListener).sheet().doRead();

        return null;
    }


    @GetMapping("/findOrderSettingListByOrderDate/{date}")
    public Result findOrderSettingListByOrderDate(@PathVariable("date")String date ) throws ParseException {

//        return "1111111";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date newDate = format.parse(date);

        List<OrderSettingDTO> orderSettingDTOList = orderSettingService.findOrderSettingListByOrderDate(newDate);
        return new Result(true,"根据日期查询预约信息成功",orderSettingDTOList);
    }


    @PutMapping("/updateOrderSettingByOrderDate/{orderDate}/{value}")
    public Result updateOrderSettingByOrderDate(@PathVariable("orderDate")Date orderDate,@PathVariable("value")Integer value ) throws ParseException {

      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String newDate = format.format(orderDate);

        orderSettingService.updateOrderSettingByOrderDate(newDate,value);
        return new Result(true,"根据日期查询预约信息成功");
    }


}
